package Algorithm.Sort;

public class QuickSort {
    public static void main(String[] args) {
        int[] arr = {2, 6, 9, 8, 7, 26, 13, 42, 36, 99};
        printArray(arr);
        function(arr, 0, arr.length - 1);
        printArray(arr);
    }

    public static void function(int[] arr, int left, int right) {
        //递归出口
        if (left >= right) {
            return;
        }
        int i = left;
        int j = right;
        int key = arr[left];
        while (i < j) {
            while (i < j && arr[j] >= key) {
                j--;
            }
            while (i < j && arr[i] <= key) {
                i++;
            }
            if (i < j) {
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        int temp = arr[i];
        arr[i] = arr[left];
        arr[left] = temp;
        function(arr, left, i - 1);
        function(arr, i + 1, right);
    }

    public static void printArray(int[] arr) {
        for (int num : arr) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
    /*public static void function2(int[] arr,int left,int right){
        while (left>=right){
            return;
        }
        int key=arr[left];
        while (left<right){
            while (key<arr[right]) {
                right--;
            }
            while (key>=arr[left]){
                left++;
            }
            if(){

            }
        }
    }*/
}
